package com.zjun.exception;

import com.zjun.errorCode.IErrorCode;
import lombok.Getter;
import org.apache.logging.log4j.util.Strings;

import java.util.Optional;

/**
 * 项目三种种类异常:客户端异常，服务端异常以及远程服务异常
 *
 */
@Getter
public abstract class AbstractException extends RuntimeException {
    public final String errorCode;
    public final String errorMessage;
    public AbstractException(String message, Throwable throwable, IErrorCode errorCode){
        this.errorCode = errorCode.errorCode();
        this.errorMessage = Optional.ofNullable(message)
                .filter(s -> !s.isBlank()) // 检查 null、空字符串或纯空格
                .orElse(errorCode.message());
    }
}
